feat: add Windows/PowerShell support#21
Conversation
Greptile SummaryAdds PowerShell/Windows support by introducing skip regexes for PS variable prefixes and Verb-Noun cmdlets, splitting on newlines in addition to
|
| Filename | Overview |
|---|---|
| src/index.ts | Core logic update: adds PowerShell skip/cmdlet regexes, newline splitting via OPERATOR_RE, heredoc detection with fallback to OPERATOR_ONLY_RE, and the snipSegment helper for per-segment pipe handling. All previously raised issues are correctly addressed. |
| src/index.test.ts | 14 new test cases covering PowerShell env vars, cmdlets (including ForEach-Object and ConvertTo-Json), call operator, splatting, newline splitting, and heredoc safety; all three previously flagged gaps now have direct coverage. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[toolExecuteBefore] --> B{starts with snip?}
B -- yes --> Z[return unchanged]
B -- no --> C{HEREDOC_RE detected?}
C -- yes --> D[use OPERATOR_ONLY_RE]
C -- no --> E[use OPERATOR_RE with newlines]
D --> F[split on separator]
E --> F
F --> G{single segment?}
G -- yes --> H[snipSegment]
G -- no --> I[map segments]
I --> J{is operator token?}
J -- yes --> K[keep as-is]
J -- no --> H
H --> L[findFirstPipe]
L --> M{pipe found?}
M -- yes --> N[snipCommand firstCmd plus rest]
M -- no --> O[snipCommand segment]
N --> P[snipCommand]
O --> P
P --> Q{unproxyable cmd?}
Q -- yes --> Z
Q -- no --> R{POWERSHELL_SKIP_RE?}
R -- yes --> Z
R -- no --> S{POWERSHELL_CMDLET_RE?}
S -- yes --> Z
S -- no --> T[prepend snip]
Reviews (3): Last reviewed commit: "feat: add Windows/PowerShell support" | Re-trigger Greptile
| // PowerShell: segments starting with these chars are never external commands. | ||
| // $ → variable/assignment ($env:CI='true', $x = 1) | ||
| // @ → here-string, splat, array (@", @(), @{}) | ||
| // & → call operator (& "path\to\exe") | ||
| // { → script block | ||
| const POWERSHELL_SKIP_RE = /^[$@&{]/ |
There was a problem hiding this comment.
@-prefix path lacks test coverage
POWERSHELL_SKIP_RE includes @ to handle PowerShell here-strings (@"), splatting (@args), and array literals (@()), but there is no corresponding test. A test for e.g. @args or @("a","b") would confirm the skip path actually works and guard against future refactors.
| // PowerShell: segments starting with these chars are never external commands. | |
| // $ → variable/assignment ($env:CI='true', $x = 1) | |
| // @ → here-string, splat, array (@", @(), @{}) | |
| // & → call operator (& "path\to\exe") | |
| // { → script block | |
| const POWERSHELL_SKIP_RE = /^[$@&{]/ | |
| // PowerShell: segments starting with these chars are never external commands. | |
| // $ → variable/assignment ($env:CI='true', $x = 1) | |
| // @ → here-string, splat, array (@", @(), @{}) | |
| // & → call operator (& "path\to\exe") | |
| // { → script block | |
| // NOTE: add a test for @-prefixed segments (splatting / here-strings) in index.test.ts | |
| const POWERSHELL_SKIP_RE = /^[$@&{]/ |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
284163d to
b099f1a
Compare
|
Both review findings addressed in the latest force-push (b099f1a):
All 48 tests pass (30 original + 18 new). |
- Detect and skip PowerShell env var assignments (\='Y')
- Detect and skip PowerShell Verb-Noun cmdlets (Write-Output, Get-ChildItem, etc.)
- Detect and skip PowerShell special syntax (\$, @, &, {)
- Add newline splitting to OPERATOR_RE so multi-line commands are snipped per-line
- Extract snipSegment helper for per-segment pipe handling
- Add 14 tests covering PowerShell patterns and newline splitting
b099f1a to
0177604
Compare
|
Addressed the P1 heredoc finding in the latest push (0177604): Heredoc commands silently broken by Also fixed a subtle bug where the Added 3 heredoc safety tests:
All 51 tests pass (30 original + 21 new). |
Fixes #20.
What
Adds Windows/PowerShell support to the snip plugin. On Windows, opencode drives PowerShell, not bash. The plugin previously assumed a POSIX shell, which caused it to:
$env:X='Y'assignments withsnip, silently dropping all non-interactive environment guardsWrite-Output,Get-ChildItem, etc.) as binaries, which failscdwhen separated by a newline (not;/&&)Changes
src/index.tsPOWERSHELL_SKIP_RE: skip segments starting with$,@,&,{— these are PowerShell variable assignments, here-strings, call operators, and script blocks that can never be external commandsPOWERSHELL_CMDLET_RE: skip Verb-Noun cmdlets (Write-Output,Get-ChildItem,Set-Location, etc.) — these are shell builtins thatsnipcannot execOPERATOR_RE: split on\r?\nin addition to;,&&,||,&— so commands on separate lines are snipped independentlysnipSegmenthelper: extracts per-segment pipe handling fromtoolExecuteBeforeso that pipe detection works correctly with newline-separated multi-line commandssrc/index.test.tsBackward compatibility
$-prefixed commands don't exist in bash, Verb-Noun patterns don't match standard Unix tools, and newline splitting is correct for multi-line bash commands toosnipCommandfunction signature and behavior for POSIX inputs is identical